package com.neuedu.listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

//@WebListener
public class MySessionListener implements  HttpSessionListener, HttpSessionAttributeListener {

    public MySessionListener() {
    }



    @Override
    public void sessionCreated(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        Object source = se.getSource();
        System.out.println("MySessionListener.sessionCreated");
        System.out.println("session = " + session);
        System.out.println("source = " + source);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        Object source = se.getSource();
        System.out.println("MySessionListener.sessionDestroyed");
        System.out.println("session = " + session);
        System.out.println("source = " + source);
    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent sbe) {
        String name = sbe.getName();
        Object value = sbe.getValue();

        System.out.printf("MySessionListener.attributeAdded       name:%s , value:%s\r\n",name,value.toString());
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
        String name = sbe.getName();
        Object value = sbe.getValue();

        System.out.printf("MySessionListener.attributeAdded       name:%s , value:%s\r\n",name,value.toString());
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
        String name = sbe.getName();
        Object value = sbe.getValue();
        Object newValue = sbe.getSession().getAttribute(name);

        System.out.printf("MySessionListener.attributeReplaced       name:%s , value:%s    ,newValue :%s  \r\n",name,value.toString() ,newValue.toString());
    }
}
